/*
 * File:   scoped_ptr.h
 * Author: dolphinigle
 *
 * Created on December 1, 2011, 3:52 PM
 */

#ifndef SCOPED_PTR_H
#define	SCOPED_PTR_H

#include <cassert>

// Analogous to boost's scoped_ptr.
// See http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/scoped_ptr.htm
template <class T>
class scoped_ptr {
public:
  scoped_ptr(T* ptr) {
    assert(ptr != NULL);
    ptr_ = ptr;
  }
  scoped_ptr() {
    ptr_ = NULL;
  }
  ~scoped_ptr() {
    if (ptr_ != NULL) {
      delete ptr_;
    }
  }
  T& operator*() {
    return *ptr_;
  }
  T* operator->() {
    return ptr_;
  }
  T* release() {
    T* tmp = ptr_;
    ptr_ = NULL;
    return tmp;
  }
  T* get() {
    return ptr_;
  }

private:

  T* ptr_;

  scoped_ptr(const scoped_ptr& orig) {
  }

  bool operator=(const scoped_ptr& orig) {
  }
};

#endif	/* SCOPED_PTR_H */

